package com.bigevent.controller;


import com.bigevent.pojo.Result;
import com.bigevent.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        //保证文件名的唯一性
        String filename = UUID.randomUUID() +originalFilename.substring(originalFilename.lastIndexOf("."));
        //转存到本地。
        //file.transferTo(new File("D:\\vscode\\vue-project\\big-event\\src\\imgfiles"+filename));
        //String url = "D:\\vscode\\vue-project\\big-event\\src\\imgfiles"+filename;
        //上传到阿里云。
        String url = AliOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
